package cn.gson.crm.controller.studentdetail;

import java.text.SimpleDateFormat;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import cn.gson.crm.controller.BaseServlet;
import cn.gson.crm.model.dao.StudentDetailDao;
import cn.gson.crm.model.entity.Position;
import cn.gson.crm.model.entity.StudentDetail;
import cn.gson.crm.model.po.StudentPayPo;

/**
 * Servlet implementation class ChangeStuDetailServlet
 */
@WebServlet("/changestu_detail")
public class CreatePayServlet extends BaseServlet {
	private static final long serialVersionUID = 1L;
	private String formJsp = "student/changestu_detail.jsp";
	private StudentDetailDao studentPayDao = new StudentDetailDao();
	protected void get(HttpServletRequest request, HttpServletResponse response) throws Exception {
		forward(formJsp);
	}

	protected void post(HttpServletRequest request, HttpServletResponse response) throws Exception {
		
		String id = request.getParameter("id");
		String gradeId =request.getParameter("gradeId");
		String name = request.getParameter("name");
		String duePay = request.getParameter("duePay");
		String havePay = request.getParameter("havePay");
		String thisPay = request.getParameter("thisPay");
		String noPay = request.getParameter("noPay");
		String empId = request.getParameter("empId");
		String payDate = request.getParameter("payDate");

		StudentPayPo stuPayList = new StudentPayPo();		
		stuPayList.setDuePay(Integer.parseInt(duePay));
		stuPayList.setHavePay(Integer.parseInt(havePay));
		stuPayList.setThisPay(Integer.parseInt(thisPay));
		stuPayList.setNoPay(Integer.parseInt(noPay));
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		stuPayList.setPayDate(sdf.parse(payDate));
			
			
				if (id == null || id.isEmpty()) {
					request.setAttribute("error", "学生姓名不能为空");
					get(request, response);
					return;
				} else if (id.trim() == null || id.trim().isEmpty()) {
					request.setAttribute("error", "学生姓名不能为空");
					get(request, response);
					return;
				}
				if (duePay == null || duePay.isEmpty()) {
					request.setAttribute("error", "应付金额不能为空！");
					get(request, response);
					return;
				} else if (duePay.trim() == null || duePay.trim().isEmpty()) {
					request.setAttribute("error", "应付金额不能为空！");
					get(request, response);
					return;
				}
				if (havePay == null || havePay.isEmpty()) {
					request.setAttribute("error", "已付金额不能为空！");
					get(request, response);
					return;
				} else if (havePay.trim() == null || havePay.trim().isEmpty()) {
					request.setAttribute("error", "已付金额不能为空！");
					get(request, response);
					return;
				}
				if (thisPay == null || thisPay.isEmpty()) { 
					request.setAttribute("error", "本次所付金额不能为空！");
					get(request, response);
					return;
				} else if (thisPay.trim() == null || thisPay.trim().isEmpty()) {
					request.setAttribute("error", "本次所付金额不能为空！");
					get(request, response);
					return;
				}	
				if (noPay == null || noPay.isEmpty()) { 
					request.setAttribute("error", "未付金额不能为空！");
					get(request, response);
					return;
				} else if (noPay.trim() == null || noPay.trim().isEmpty()) {
					request.setAttribute("error", "未付金额金额不能为空！");
					get(request, response);
					return;
				}	
				if (empId == null || empId.isEmpty()  ) { 
					request.setAttribute("error", "收款人不能为空！");
					get(request, response);
					return;
				} else if (empId.trim() == null || empId.trim().isEmpty()) {
					request.setAttribute("error", "收款人不能为空！");
					get(request, response);
					return;
				}	
				if (payDate == null || payDate.isEmpty()) { 
					request.setAttribute("error", "收款时间不能为空！");
					get(request, response);
					return;
				} else if (payDate.trim() == null || payDate.trim().isEmpty()) {
					request.setAttribute("error", "收款时间不能为空！");
					get(request, response);
					return;
				}	
				// 如果该学员已签约(gradeId小于5的均为未签约学员)并且id不为空 则开始创建收款
				if (gradeId == "1"||gradeId =="2" ||gradeId =="3"||gradeId == "4") {
					request.setAttribute("error", "该学员未签约不能进行缴费");
					get(request,response);
					return;
				} 
		}
		
}

